package com.itcam.web.controller.chat;

import com.itcam.chat.domain.vo.MessageVo;
import com.itcam.chat.domain.vo.QueryVo;
import com.itcam.chat.service.OllamaService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@Tag(name = "AI大模型交互")
@RestController
@RequestMapping("/ai")
public class OllamaController {

    @Autowired
    private OllamaService ollamaService;

    /**
     * 文本问答
     * @param queryVo
     * @return
     */
    @Operation(summary = "文本问答")
    @PostMapping(value = "/chat-stream", produces = "text/html;charset=utf-8")
    public Flux<String> chatStream(@RequestBody QueryVo queryVo) {
        Flux<String> flux = ollamaService.chatStream(queryVo);
        return flux;
    }

    /**
     * 保存AI回答的结果
     * @param messageVo
     */
    @Operation(summary = "如果需要保存AI回答的结果，调用此接口")
    @PostMapping("/save-msg")
    public void saveMsg(@RequestBody MessageVo messageVo) {
        ollamaService.saveMsg(messageVo);
    }


}